/**
 * 2018年12月6日下午1:57:58
 * @author 谢进财
 */
package com.baihang.framework.kit;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

import com.baihang.platform.shiro.User;

/**
 * shiro权限帮助类
 *
 */
public class ShiroKit {
	/**
	 * 判断是否已经登录
	 *
	 * @return boolean
	 */
	public static boolean isAuthed() {
		Subject subject = SecurityUtils.getSubject();
		if (subject == null || subject.getPrincipal() == null || (!subject.isAuthenticated() && !subject.isRemembered())) {
			return false;
		} else {
			return true;
		}
	}
	
	public static void logOut() {
		SecurityUtils.getSubject().logout();
	}
	/**
	 * 获取当前用户
	 * @return
	 */
	public static User getCurrentUser() {
		Subject subject = SecurityUtils.getSubject();
		if (subject != null) {
			return (User) subject.getPrincipal();
		}
		return null;
	}

}
